package com.example.aitasks.web;

import com.example.aitasks.service.AiService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/chat")
public class ChatController {
    private final AiService ai;

    public ChatController(AiService ai) { this.ai = ai; }

    public record ChatReq(String message, String model){}
    public record ChatResp(String reply){}

    @PostMapping
    public ChatResp chat(@RequestBody ChatReq req) throws Exception {
        String system = "You are a helpful assistant for configuring AI analysis tasks. Keep answers short.";
        String content = ai.summarizeToJson(req.model(), system, req.message());
        return new ChatResp(content);
    }
}
